<%-- 
    Document   : formulario
    Created on : 28-may-2012, 16:44:45
    Author     : Administrador
--%>
<%@page import="com.javabeans.Horario"%>
<%@page import="com.javabeans.PeriodoDia"%>
<%@page import="com.javabeans.DiaSemana"%>

<%@include file="../../../../controlSession.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    int i = 0;
    int accion = 4; // 4 = registra un nuevo periodo dia and 6 = edita en periodo dia
    boolean isNew = true;
    int idFacultad = Integer.parseInt(request.getParameter("idFacultad"));
    String nomFac = request.getParameter("nomFac");
    int idPeriodoDia = 0;
    String horaIni = "";
    String horaFin = "";
    int[] idDias = null;
    List<DiaSemana> diasSemana = (List<DiaSemana>)request.getAttribute("diasSemana");
    if(request.getAttribute("PeriodoDia") != null){
        accion = 6;
        isNew = false;
        PeriodoDia pd = (PeriodoDia)request.getAttribute("PeriodoDia");
        idPeriodoDia = pd.getIdPeriodoDia();
        horaIni = pd.getHoraIni();
        horaFin = pd.getHoraFin();
        String dias = (String)request.getAttribute("dias");
        if(dias.length() > 0){
            String[] auxs = dias.split("_");
            idDias = new int[auxs.length];
            for(String x:auxs){
                idDias[i] = Integer.parseInt(x);
                i++;
            }
       }
    }
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>SI-ESFM </title>
        <meta name="description" content="Derechos Reservados SI-ESFM." />
        <link rel="stylesheet" href="<%=s_path%>/css/styles.css" type="text/css" />
        <link rel="stylesheet" href="<%=s_path%>/css/menu/style.css" type="text/css" />
        <link rel="shortcut icon" href="<%=s_path%>/images/ico.png" type="image/png"/>
        <link rel="stylesheet" href="<%=s_path%>/css/themes/start/jquery-ui-1.8.20.custom.css" type="text/css" />
        <link rel="stylesheet" href="<%=s_path%>/css/themes/start/jquery.ui.timepicker.css?v=0.3.0" type="text/css" />
        
        <script type="text/javascript" src="<%=s_path%>/js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/validate/jquery.validate.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/jquery.form.js"></script>
        
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.ui.core.min.js"></script>  <!--si o si cargar esto-->
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.ui.widget.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.ui.tabs.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/ui/minified/jquery.ui.position.min.js"></script>
        <script type="text/javascript" src="<%=s_path%>/js/ui/jquery.ui.timepicker.js?v=0.3.0"></script>
        <!-- fin time -->
        <script type="text/javascript" src="<%=s_path%>/js/comun.js"></script>
        <script type="text/javascript">
            function newP(){
                // accion = 11 = nuevo periodo dia
                location.href = "Administracion?accion=40";
            }
            
            function edit(idDiaPeriodo,dias){
                var sbody = "accion=41&idDiaPeriodo="+idDiaPeriodo+"&dias="+dias;
                location.href = "Administracion?"+sbody;
            }
            
            $(document).ready(function() {
                $('#timepicker_start').timepicker({
                    showLeadingZero: false,
                    onHourShow: tpStartOnHourShowCallback,
                    onMinuteShow: tpStartOnMinuteShowCallback
                });
                $('#timepicker_end').timepicker({
                    showLeadingZero: false,
                    onHourShow: tpEndOnHourShowCallback,
                    onMinuteShow: tpEndOnMinuteShowCallback
                });
                
                $("#addPeriodo").click(function() {
                    alert("click en addPeriodo");
                });
                
                $('#formPeriodo').ajaxForm({
                    beforeSubmit: validateCarga,
                    beforeSend:function(obj){
                        $('#divForm').css({display:'none'});
                        $('#imgLoad').css({display:'block'});
                    },
                    success: function(res, statusText, xhr, form){
                       $("#divRes").html(res);
                       $("#divRes").css({display:'block'});
                    },
                    complete:function(){
                       $('#imgLoad').css({display:'none'});
                    },
                    error:function(){
                       alert("error! al registrar el periodo dia.");
                    }
		});
            });
            
            // funcion para validar
            function validateCarga(formData, jqForm, options) {
                var bandera = $("#formPeriodo").valid();
                return bandera;
            }
            
            function tpStartOnHourShowCallback(hour) {
                var tpEndHour = $('#timepicker_end').timepicker('getHour'); // es para restringir hora
                tpEndHour = 23;
                // Check if proposed hour is prior or equal to selected end time hour
                if (hour <= tpEndHour) { return true; } // tb pa restringir hora
                // if hour did not match, it can not be selected
                return false;
            }
            function tpStartOnMinuteShowCallback(hour, minute) {
                
                var tpEndHour = $('#timepicker_end').timepicker('getHour');
                tpEndHour = 23;
                var tpEndMinute = $('#timepicker_end').timepicker('getMinute');
                tpEndMinute = 59;
                // Check if proposed hour is prior to selected end time hour
                if (hour < tpEndHour) { return true; }
                // Check if proposed hour is equal to selected end time hour and minutes is prior
                if ( (hour == tpEndHour) && (minute < tpEndMinute) ) { return true; }
                // if minute did not match, it can not be selected
                
                return false;
            }

            function tpEndOnHourShowCallback(hour) {
                var tpStartHour = $('#timepicker_start').timepicker('getHour');
                // Check if proposed hour is after or equal to selected start time hour
                if (hour >= tpStartHour) { return true; }
                // if hour did not match, it can not be selected
                return false;
            }
            
            function tpEndOnMinuteShowCallback(hour, minute) {
                var tpStartHour = $('#timepicker_start').timepicker('getHour');
                var tpStartMinute = $('#timepicker_start').timepicker('getMinute');
                // Check if proposed hour is after selected start time hour
                if (hour > tpStartHour) { return true; }
                // Check if proposed hour is equal to selected start time hour and minutes is after
                if ( (hour == tpStartHour) && (minute > tpStartMinute) ) { return true; }
                // if minute did not match, it can not be selected
                return false;
            }
            
            function ir_a_horarios(idFacultad){
                location.href = "Administracion?accion=2&idFacultad="+idFacultad;
            }
            
            function addPeriodo(){
                document.getElementById("divForm").style.display = "block";
                document.getElementById("divRes").style.display = "none";
                resetear();
            }
            
            function resetear(){
                $('#formPeriodo').each(function(){
                    this.reset();
                });
            }
        </script>
    </head>
    <body onload="showTime(<%=s_param%>);resetear()">
        <div id="top-wrap">
            <!-- cabeza principal -->
            <%@include file="../../../../head.jsp" %>
            
            <!-- cuerpo -->
            <div id="bodySpace">               
                <!-- aqui va la ruta -->
                <div class="clearfix" id="middle" style="position: absolute">
                    <!-- aqui va el arbol de entrada -->
                    <div id="breadcrumb"><!-- le da la forma de la imagen -->
                        <ul>
                        <li><a href="<%=s_path%>/principal.jsp">Home</a></li>
                        <li><span style="color:#666">Administraci&oacute;n</span></li>
                        <li><span style="color:#666">Administraci&oacute;n General</span></li>
                        <li class="current-page"><span class="end"><span class="middle">Formulario</span></span></li>
                        </ul>                        
                    </div><!-- begin SIDEBAR FIRST -->
                </div>
                
                <div id="principal">
                    <!-- izquierda -->
                    <div class="cuerpo2y" style="border: 0px solid"><br/><br/><!-- estos break son necesarios ya q uso absolute en css  cuerpo izquierdo-->
                        <div class="izq">
                            <%@include file="../../../../bodyIzq.jsp" %>
                        </div>
                        <div class="medio" style="border: 0px solid">
                            <div id="imgLoad" style="float: left;width: 84%;display: none;"><img src="<%=s_path%>/images/imgLoad/ajax-loader.gif" width="32" height="32" alt="ajax-loader.gif" style="position:absolute; top:50%; left:50%;"/></div>
                            <div id="divForm">
                            <h2 class="decorado"><%=(isNew)?"Nuevo Periodo D&iacute;a":"Modificar Periodo D&iacute;a"%></h2><br/>
                                <form id="formPeriodo" method="post" action="Administracion?accion=<%=accion%>">
                                    <input type="hidden" name="idPeriodoDia" id="idPeriodoDia" value="<%=idPeriodoDia%>" />
                                    <input type="hidden" name="idFacultad" id="idFacultad" value="<%=idFacultad%>" />
                                    <div style="clear:both;">
                                        <label class="form_align43">Unidad Acad&eacute;mica : </label>&nbsp;
                                        <%=nomFac%>
                                    </div><br/>
                                    <div style="clear:both;">
                                        <label class="form_align43">Hora Inicio : </label>
                                        <input type="text" style="width: 70px" name="timepicker_start" id="timepicker_start" value="<%=horaIni%>" readonly="true" class="required form_input_align" />
                                        <label class="error">*</label>
                                    </div><br/>
                                    <div style="clear:both;">
                                        <label class="form_align43">Hora Fin : </label>
                                        <input type="text" style="width: 70px" name="timepicker_end" id="timepicker_end" value="<%=horaFin%>" readonly="true" class="required form_input_align" />
                                        <label class="error">*</label>
                                    </div><br/>
                                    
                                    <div style="clear:both;">
                                        <label class="form_align43">Dias habilitados : </label>
                                            <div style="float: left">
                                    <%
                                        for(DiaSemana ds:diasSemana){
                                            boolean flag = false;
                                            if(idDias != null){
                                                for(int id:idDias){
                                                    if(ds.getIdDiaSemana() == id)
                                                        flag = true;
                                                }
                                            }
                                            out.println("<div>&nbsp;&nbsp;<input type='checkbox' name='diasSemana' id='"+ds.getIdDiaSemana()+"' "+((flag)?"checked='true'":"")+" value='"+ds.getIdDiaSemana()+"_"+ds.getNombre()+"' class='required' /><label for="+ds.getIdDiaSemana()+">&nbsp;&nbsp;"+ds.getNombre()+"</label></div>");
                                        }
                                    %>  <br/>
                                            </div>
                                        <label class="error">*</label>
                                    </div><br/>
                                    
                                    <div class="form_center" style="clear:both;">
                                        <input type="submit" value="<%=(isNew)?"Registrar":"Modificar"%>" class="boton" title="Pulsa aqui para <%=(isNew)?"Registrar":"Modificar"%>" />
                                        <input type="button" value="Cancelar" onclick="ir_a_horarios(<%=idFacultad%>)" class="boton" title="Pulsa aqui para cancelar"/>
                                    </div>
                                </form>
                            </div>
                            <div id="divRes" style="display: none"></div>
                        </div>
                    </div><!--end of leftPan-->
                    
                    <div class="yDer" style="border: 1px solid #ccc;">
                        <%@include file="../../../../publicidad.jsp" %>                       
                    </div><!--end of rightPan-->
                </div><!--end of content-wrapper-->
            </div><!--end of body-wrap-->
            
            <!-- footer -->
        </div>
    </body>
</html>


